﻿using _011_Dapper_mysql_study.dto;
using System;
using System.Collections.Generic;

namespace _011_Dapper_mysql_study
{
    class Program
    {
        static void Main(string[] args)
        {
            string sql;


            //插入
            Teacher teacher = new Teacher() { NameStr = Guid.NewGuid().ToString() };
            sql = "insert into teacher(Name) values(@NameStr)";
            DapperHelper.InsertObj(sql, teacher);


            //查询
            sql = "select Id,Name as NameStr from teacher";
            List<Teacher> list = DapperHelper.SelectObj<Teacher>(sql);
            list.ForEach(it => Console.WriteLine(it.print()));

            Console.WriteLine("------------------------------");

            //子查询
            sql = "select t1.*,t2.id,t2.name as NameStr from student t1 inner join teacher t2 on t1.tid = t2.id";
            List<Student> students = DapperHelper.SelectObj<Student,Teacher>(sql);
            students.ForEach(it => Console.WriteLine(it.print()));
        }
    }
}
